package ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import net.ck.hzq.R;

import java.util.Date;
import java.util.List;

import Utils.StringUtil;
import ui.model.RewardsTrainTopBean;
import util.SysUtils;
import widget.expandable.ExpandableAdapter;

public class RewardsOtherAdapter extends ExpandableAdapter<RewardsTrainTopBean.RecordsBean, RewardsOtherAdapter.GroupViewHolder, RewardsTrainTopBean.RecordsBean.ListBean, RewardsOtherAdapter.ChildViewHolder> {

    private Context mContext;
    private int mType;


    public RewardsOtherAdapter(Context context, List<RewardsTrainTopBean.RecordsBean> list, int type) {
        super(context, list);
        mContext = context;
        mType = type;
    }

    @Override
    public RewardsTrainTopBean.RecordsBean getGroup(int postion) {
        return getList().get(postion);
    }

    @Override
    public RewardsTrainTopBean.RecordsBean.ListBean getChild(RewardsTrainTopBean.RecordsBean groupBean, int grouppostion, int childPostion) {
        return groupBean.getList().get(childPostion);
    }

    @Override
    public int getChildCount(int groupBeanPostion) {
        if (getGroup(groupBeanPostion).getList() != null)
            return getGroup(groupBeanPostion).getList().size();
        return 0;
    }

    @Override
    public int getGroupLayout() {
        return R.layout.item_rewards_parent;
    }

    @Override
    public GroupViewHolder getGroupViewHolder(View v) {
//        v.setBackgroundColor(Color.RED);
        return new GroupViewHolder(v);
    }

    @Override
    public void initGroupWidget(GroupViewHolder qqGroupAdapterViewHolder, View Groupview) {
        qqGroupAdapterViewHolder.groupName = findviewById(Groupview, R.id.item_rewards_details_parent_title);
        qqGroupAdapterViewHolder.groupMoney = findviewById(Groupview, R.id.item_rewards_details_parent_money);
        qqGroupAdapterViewHolder.right = findviewById(Groupview, R.id.item_rewards_details_parent_right);
    }

    @Override
    public void bindGroupView(GroupViewHolder qqGroupAdapterViewHolder, RewardsTrainTopBean.RecordsBean groupBean, boolean isOPen) {
        qqGroupAdapterViewHolder.groupName.setText(groupBean.getEntityName());
        qqGroupAdapterViewHolder.groupMoney.setText("奖励金额：" + StringUtil.getFormatPrice(groupBean.getAmount()) + "元");
        if (isOPen) {
            qqGroupAdapterViewHolder.right.setBackgroundResource(R.mipmap.ic_rewards_down);
        } else {
            qqGroupAdapterViewHolder.right.setBackgroundResource(R.mipmap.ic_rewards_right);
        }
    }

    @Override
    public int getChildLayout() {
        return R.layout.item_rewards_details;
    }

    @Override
    public ChildViewHolder getChildViewHolder(View view) {
        return new ChildViewHolder(view);
    }

    @Override
    public void initChildViewWidget(ChildViewHolder childViewHolder, View view) {
        childViewHolder.name = findviewById(view, R.id.item_rewards_details_title);
        childViewHolder.time = findviewById(view, R.id.item_rewards_details_time);
        childViewHolder.titile = findviewById(view, R.id.item_rewards_details_number);
        childViewHolder.money = findviewById(view, R.id.item_rewards_details_money);
    }

    @Override
    public void bindChildView(final ChildViewHolder childViewHolder, final RewardsTrainTopBean.RecordsBean.ListBean b, int groupindex) {
        childViewHolder.name.setText(b.getBuyerName() + "");
        childViewHolder.time.setText(SysUtils.sf6.format(new Date(b.getCreateTime())));
        childViewHolder.titile.setTextColor(Color.parseColor("#333333"));
        childViewHolder.titile.setText("采购台数:" + b.getBuyCount() + "台");
    }

    public class GroupViewHolder extends ExpandableAdapter.ViewHolder {
        TextView groupName;
        TextView groupMoney;
        ImageView right;

        public GroupViewHolder(View itemView) {
            super(itemView);
        }
    }

    public class ChildViewHolder extends ExpandableAdapter.ViewHolder {
        TextView name;
        TextView time;
        TextView titile;
        TextView money;


        public ChildViewHolder(View itemView) {
            super(itemView);
        }
    }


}
